#ifndef _SINGLE_HPP
#define _SINGLE_HPP
#include <Windows.h>
#include <process.h>

namespace com_oocl_monitor {
	namespace system
	{
		template <typename T>
		class Single
		{
		public:
			static T* getInstance();
		protected:
			Single() {}
			~Single() {}
		private:
			static T* _instance;
			static SRWLOCK _lock;
		private:
			Single(const Single&);
			Single& operator=(const Single&);
		};

		template <typename T>
		T* Single<T>::_instance = nullptr;

		template <typename T>
		SRWLOCK Single<T>::_lock = SRWLOCK_INIT;


		template <typename T>
		T* Single<T>::getInstance()
		{
			AcquireSRWLockExclusive(&_lock);
			if (_instance == nullptr)
			{
				_instance = new T;
			}
			ReleaseSRWLockExclusive(&_lock);
			return _instance;
		}

	}
}
#endif // _SINGLE_HPP
